<template>
    <div class="search_body">
        <div class="search_input">
            <div class="search_input_wrapper">
                <i class="iconfont icon-sousuo"></i>
                <input type="text" v-model="message">
            </div>					
        </div>
        <div class="search_result">
            <h3>电影/电视剧/综艺</h3>
            <ul>
                <li v-for="item in moviesList" :key="item.id">
                    <div class="img"><img :src="item.img | setWH('128.180')"></div>
                    <div class="info">
                        <p><span>{{item.nm}}</span><span>{{item.sc}}</span></p>
                        <p>{{item.enm}}</p>
                        <p>{{item.cat}}</p>
                        <p>{{item.rt}}</p>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
export default {
    name:'Search',
    data(){
        return{
            message:"",
            moviesList:[],
            timer:'',
            prevCityId:-1
        }
    },
    watch:{
        message(newVal){
            if(newVal=="")this.moviesList = [];
            else{
                clearTimeout(this.timer);
                let that = this;
                this.timer = setTimeout(()=>{
                    that.reqRes(newVal);
                },1000)
            }
        },
    },
    methods:{
        reqRes(newVal){
            var cityId = this.$store.state.city.id;
            if(this.prevCityId === cityId)return;
            this.axios.get("/ajax/ajax/search?kw="+newVal+"&cityId="+cityId+"&stype=-1").then(res=>{
                let movies = res.data.movies;
                if(res.statusText == "OK" && movies){
                    this.moviesList = movies.list;
                    this.prevCityId = cityId;
                } 
            })
        }
    },
}
</script>

<style scoped lang="scss">
.search_body{
    overflow: auto;
    flex: 1;
    .search_input{
        padding: 8px 10px;
        background: #f5f5f5;
        border-bottom: 1px solid #e5e5e5;
        .search_input_wrapper{
            padding: 0 10px;
            border: 1px solid #e6e6e6;
            border-radius: 5px;
            background: white;
            line-height: 20px;
            display: flex;
            i{
                padding: 4px 0;
                font-size: 16px;
            }
            input{
                border: none;
                margin-left: 5px;
                padding: 4px 0;
                color: #333;
                font-size: 13px;
                outline: none;
                width: 100%;
            }
        }
    }
    .search_result{
        h3{
            padding: 9px 15px;
            color: #999;
            font-size: 15px;
            border-bottom: 1px solid #e6e6e6;
        }
        ul{
            li{
                display: flex;
                padding: 10px 15px;
                border-bottom: 1px #c9c9c9 dashed;
                box-sizing: border-box;
                .img{
                    float: left;
                    width: 60px;
                    img{
                        width: 100%;
                    }
                }
                .info{
                    float: left;
                    margin-left: 15px;
                    flex: 1;
                    p{
                        display: flex;
                        justify-content: space-between;
                        height: 22px;
                        line-height: 22px;
                        font-size: 12px;
                        span:nth-child(1){
                            font-size: 18px;
                            flex: 1;
                        }
                        span:nth-child(2){
                            font-size: 16px;
                            color: #fc7103;
                        }
                    }
                }
            }
        }
    }
}
</style>